//
//  MCCameraImageHandle.m
//  CreditGroup
//
//  Created by ltl on 15/9/12.
//  Copyright (c) 2015年 JPlay. All rights reserved.
//

#import "MCCameraImageRotationHandle.h"

@implementation MCCameraImageRotationHandle

+(UIImage *)processImagesWithType:(EMCImageRotationType)type image:(UIImage *)image
{
    switch (type)
    {
        case kMCImageRotationTypeNone:
            return image;
            break;
        case kMCImageRotationTypeLeft:
            return [MCCameraImageRotationHandle processImagesWithrRotateToLeft:image];
            break;
        case kMCImageRotationTypeRight:
            return [MCCameraImageRotationHandle processImagesWithrRotateToRight:image];
            break;
        case kMCImageRotationTypeDown:
            return [MCCameraImageRotationHandle processImagesWithrRotateToDown:image];
            break;
            
        default:
            break;
    }
    return  nil;
}

// 图片向左90度旋转处理
+(UIImage *)processImagesWithrRotateToLeft:(UIImage *)image
{
    
    switch (image.imageOrientation)
    {
        case UIImageOrientationUp:
            return [UIImage imageWithCGImage:image.CGImage scale:1 orientation:UIImageOrientationLeft];
            break;
        case UIImageOrientationLeft:
            return [UIImage imageWithCGImage:image.CGImage scale:1 orientation:UIImageOrientationDown];
            break;
        case UIImageOrientationRight:
            return [UIImage imageWithCGImage:image.CGImage scale:1 orientation:UIImageOrientationUp];
            break;
        case UIImageOrientationDown:
            return [UIImage imageWithCGImage:image.CGImage scale:1 orientation:UIImageOrientationRight];
            break;
            
        default:
            break;
    }
    
    return image;
}

// 图片向下180度旋转处理
+(UIImage *)processImagesWithrRotateToDown:(UIImage *)image
{
 
    switch (image.imageOrientation)
    {
        case UIImageOrientationUp:
            return [UIImage imageWithCGImage:image.CGImage scale:1 orientation:UIImageOrientationDown];
            break;
        case UIImageOrientationLeft:
            return [UIImage imageWithCGImage:image.CGImage scale:1 orientation:UIImageOrientationRight];
            break;
        case UIImageOrientationRight:
            return [UIImage imageWithCGImage:image.CGImage scale:1 orientation:UIImageOrientationLeft];
            break;
        case UIImageOrientationDown:
            return [UIImage imageWithCGImage:image.CGImage scale:1 orientation:UIImageOrientationUp];
            break;
            
        default:
            break;
    }

    
    return image;
}
// 图片向右90度旋转处理
+(UIImage *)processImagesWithrRotateToRight:(UIImage *)image
{
    switch (image.imageOrientation)
    {
        case UIImageOrientationUp:
            return [UIImage imageWithCGImage:image.CGImage scale:1 orientation:UIImageOrientationRight];
            break;
        case UIImageOrientationLeft:
            return [UIImage imageWithCGImage:image.CGImage scale:1 orientation:UIImageOrientationUp];
            break;
        case UIImageOrientationRight:
            return [UIImage imageWithCGImage:image.CGImage scale:1 orientation:UIImageOrientationDown];
            break;
        case UIImageOrientationDown:
            return [UIImage imageWithCGImage:image.CGImage scale:1 orientation:UIImageOrientationLeft];
            break;
            
        default:
            break;
    }
    return image;
}



@end
